<?php
// 本类由系统自动生成，仅供测试用途
class LoginAction extends Action {
	private $admin;
	public function __construct(){
        parent::__construct();
        $this->admin=D('Admin');


	}
	public function index(){
		$d['id']=1;
		$d['username']='admin';
        $d['password']=md5('abc567');
		$this->admin->save($d);
        $this->display('./Tpl/Admin/login.html');
	}

	public function go(){
	    $username = $_POST['username'];
		$password = md5($_POST['password']);
        $user = $this->admin->where('username=\''.$username.'\'')->find();

		if($user){
		    if($user['password']==$password){
			    $_SESSION['USER_ADMIN_KEY']=$username;
				$_SESSION['USER_ADMIN_ID']=$user['id'];

                $data['id']=$user['id'];
				$data['logintime']=date('Y-m-d H:i:s',time());
				$data['loginip']=get_client_ip();
				$this->admin->save($data);

                echo '<script language="javascript">top.location.href="/?s=Admin/";</script>';
			}else{
				$this->assign('jumpUrl','/?s=Admin/Login');
				$this->error('用户名或密码错误！');
			}
		}else{
		    $this->assign('jumpUrl','/?s=Admin/Login');
			$this->error('该用户不存在！');
		}
	}

	public function loginout(){
		session(null);
		echo '<script language="javascript">top.location.href="/?s=Admin/Login";</script>';
	}
}
?>